package command
{
	import com.adobe.cairngorm.commands.Command;
	import com.adobe.cairngorm.control.CairngormEvent;
	
	import event.TripManagerEvent;
	
	import model.Model;
	import model.tree.PictureNode;
	import model.tree.TripNode;
	
	import mx.collections.ArrayCollection;
	import mx.rpc.CallResponder;
	import mx.rpc.IResponder;
	import mx.rpc.events.FaultEvent;
	import mx.rpc.events.ResultEvent;
	
	import services.databasewrapper.DatabaseWrapper;
	import services.picturehandler.PictureHandler;
	
	import valueObjects.VOPicture;
	import valueObjects.VOTrip;
	
	public class GetMyPicturesCommand implements IResponder, Command
	{
		
		/***************************
		 *   Attributes
		 **************************/ 
		
		
		
		public function result(data:Object):void
		{
			if(Model.instance.myPictures == null) Model.instance.myPictures = new ArrayCollection();
			// remove all the existing trips
			Model.instance.myPictures.removeAll();
			//trace(data.result.source);
			for each (var picture:VOPicture in data.result.source)
			{
				//trace(picture);
				Model.instance.myPictures.addItem(new PictureNode(picture));
			}	
		}
		
		public function fault(info:Object):void
		{
		}
		
		public function execute(event:CairngormEvent):void
		{
			var userId:int = (event as TripManagerEvent).additionalData.userId;
			var tripId:int = (event as TripManagerEvent).additionalData.tripId;
			var placeId:int = (event as TripManagerEvent).additionalData.placeId;
			// creating a new database Wrapper
			var pictureHandler:PictureHandler = new PictureHandler();
			pictureHandler.addEventListener(FaultEvent.FAULT, fault);
			pictureHandler.addEventListener(ResultEvent.RESULT, result);
			pictureHandler.getMyPictures(userId,tripId, placeId);
			
		}
	}
}